package com.algorithm.hqy;

/**
 * @Classname ArrayQueue
 * @Date 2019/9/16 14:11
 * @auther by hqy
 */
public class ArrayQueue {

    private int maxSize;

    private int front;

    private int rear;

    private int array[];

    public ArrayQueue(int maxSize) {
        this.maxSize = maxSize;
        front = -1;
        rear = -1;
        array = new int[maxSize];
    }

    public boolean isFull() {
        return rear + 1 == maxSize;
    }

    public boolean isEmpty() {
        return rear == front;
    }

    public void addNum(int num) {
        if (isFull()) {
            throw new RuntimeException("队列已满，不能添加");
        }
        rear = rear + 1;
        array[rear] = num;
    }

    /**
     * @param []
     * @return int
     * @Description 这种数组模拟队列的方法，取完这个数后，这个数实际上还是存在于这个队列中的。
     */
    public int getNum() {
        if (isEmpty()) {
            throw new RuntimeException("队列已空，不能取出数据");
        }
        front = front + 1;
        return array[front];
    }

    /**
     * @param []
     * @return void
     * @Description 展示出队列中的现有数据
     */
    public void showQuere() {
        if (isEmpty()) {
            throw new RuntimeException("队列已空~~~~~");
        }

        for (int i = front + 1; i <= rear; i++) {
            System.out.printf("array[%d]=%d \n", i, array[i]);
        }
    }
}

